﻿using System;
using System.Diagnostics.Tracing;
using System.IO;

namespace NewsReader.Log
{
    public static class LoggerExtensions
    {
        public static void DebugFormat(this Logger logger,  string format, params object[] args)
        {
           logger.Debug(string.Format(format, args));
        }

        public static void InfoFormat(this Logger logger, string format, params object[] args)
        {
            logger.Info(string.Format(format, args));
        }

        public static void WarnFormat(this Logger logger, string format, params object[] args)
        {
            logger.Warn(string.Format(format, args));
        }

        public static void ErrorFormat(this Logger logger, string format, params object[] args)
        {
            logger.Error(string.Format(format, args));
        }

        public static void CriticalFormat(this Logger logger, string format, params object[] args)
        {
            logger.Critical(string.Format(format, args));
        }
    }

    public sealed class Logger : EventSource
    {
        public static readonly Logger Log = new Logger();

        [Event(1, Level = EventLevel.Verbose)]
        public void Debug(string message)
        {
            this.WriteEvent(1, message);
        }


        [Event(2, Level = EventLevel.Informational)]
        public void Info(string message)
        {
            this.WriteEvent(2, message);
        }

        [Event(3, Level = EventLevel.Warning)]
        public void Warn(string message)
        {
            this.WriteEvent(3, message);
        }

        [Event(4, Level = EventLevel.Error)]
        public void Error(string message)
        {
            this.WriteEvent(4, message);
        }

        [Event(5, Level = EventLevel.Critical)]
        public void Critical(string message)
        {
            this.WriteEvent(5, message);
        }
    }
}
